package com.jack.helloworld.activity.mode;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/9.
 */
public class ActivityCollector {

    public static List<Activity> sActivities = new ArrayList<Activity>();

    public static void addActivity(Activity activity) {
        sActivities.add(activity);
    }

    public static void removeActivity(Activity activity) {
        sActivities.remove(activity);
    }

    public static void finishAll() {
        for (Activity activity : sActivities) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
    }

    public static void exitApp() {
        finishAll();
        android.os.Process.killProcess(android.os.Process.myPid());
    }


    /**
     * 是否有启动的Activity
     */
    public static boolean hasActivity() {
        return sActivities.size() > 0;
    }

    public static boolean activityInForeground(Activity activity) {
        return ((BaseActivity) activity).isForeground();
    }

    public static boolean hasActivityInForeground() {
        for (Activity activity : sActivities) {
            if (activityInForeground(activity)) {
                return true;
            }
        }
        return false;
    }
}
